package com.lilang.a0608provider;

import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

public class Main2Activity extends AppCompatActivity {
    ListAdapter adapter;
    private ListView list;
    List<Book> books;
    Uri uri;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        list = (ListView) findViewById(R.id.list);
        books=new ArrayList<>();
        getData();
    }

    private void getData(){
        String path="content://com.lilang.a0608provider/select_book";
        uri=Uri.parse(path);
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        while(cursor.moveToNext()){
            int id = cursor.getInt(0);
            String bookname = cursor.getString(1);
            String author = cursor.getString(2);
            books.add(new Book(id,bookname,author));
        }
        adapter=new ListAdapter(books,this);
        list.setAdapter(adapter);
    }
}
